<?php

/**
 * Name: 安全隐患验证层
 * User: Silent
 * Date: 2025-09-20
 * Time: 22:43:33
 */

namespace App\Http\Requests\Safety;

use Illuminate\Foundation\Http\FormRequest;

class SafetyHazardRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $rules = [
            'location'          => 'required|string|max:255',
            'description'       => 'required|string',
            'cover_picture'     => 'required|array',
            'cover_picture.*'   => 'required|string|url',
            'treatment_measure' => 'required|string',
        ];

        $action = optional($this->route())->getActionMethod();
        if ($action === 'update') {
            $rules['id'] = 'required|integer';
        }

        return $rules;
    }

    public function messages(): array
    {
        return [
            'location.required'          => '隐患位置不能为空',
            'description.required'       => '隐患描述不能为空',
            'cover_picture.required'     => '隐患图片不能为空',
            'cover_picture.array'        => '隐患图片格式不正确',
            'cover_picture.*.required'   => '隐患图片URL不能为空',
            'cover_picture.*.string'     => '隐患图片URL必须是字符串',
            'cover_picture.*.url'        => '隐患图片URL格式不正确',
            'treatment_measure.required' => '治理措施不能为空',
            'id.required'                => 'ID不能为空',
            'id.integer'                 => 'ID必须为整数',
        ];
    }
}
